package www.csdn.net.day56.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.bjsxt.util.DBUtils;

import util.DBConn;
import www.csdn.net.day56.bean.Admin;
import www.csdn.net.day56.dao.AdminDao;

public class AdminDaoImpl implements AdminDao {

	private Connection conn;
	private PreparedStatement pstmt;
	private ResultSet rs;

	@Override
	public Admin checkLogin(String name, String pass) {
		Admin entity = null;

		conn = DBUtils.createConn();

		String sql = "select * from admin where name=? and pass=? ";

		try {
			pstmt = conn.prepareStatement(sql);

			int index = 1;
			pstmt.setString(index++, name);
			pstmt.setString(index++, pass);

			rs = pstmt.executeQuery();

			if (rs.next()) {
				entity = new Admin();
//				entity.setId(rs.getInt("id"));
				entity.setName(rs.getString("name"));
				entity.setPass(rs.getString("pass"));
			}

		} catch (Exception e) {

		} finally {
			DBConn.release(rs, pstmt);
		}
		return entity;
	}

	@Override
	public Admin checkLogin(String name) {
		Admin entity = null;

		conn = DBConn.getConn();

		String sql = "select * from admin where name=? ";

		try {
			pstmt = conn.prepareStatement(sql);

			int index = 1;
			pstmt.setString(index++, name);
			rs = pstmt.executeQuery();

			if (rs.next()) {
				entity = new Admin();
//				entity.setId(rs.getInt("id"));
				entity.setName(rs.getString("name"));
				entity.setPass(rs.getString("pass"));
			}

		} catch (Exception e) {

		} finally {
			DBConn.release(rs, pstmt);
		}
		return entity;
	}

}